package controlador.facturas;

import controlador.ServletHelper;
import java.io.IOException;
import java.sql.Connection;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import persistencia.DetalleFacturaBean;
import persistencia.FacturaDetalleComposite;

/**
 *
 * @author Felipe
 */
@WebServlet(name = "EditarCantidadFactura", urlPatterns = {"/EditarCantidadFactura"})
public class EditarCantidadFactura extends HttpServlet {

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        Connection conexion = null;
        boolean condi = ServletHelper.validarAdmin(request, response);
        if (condi) {

            int cantidad = 1;

            String codProd = (request.getParameter("COD_PRODUCTO"));
            String strCantidad = (request.getParameter("CANTIDAD"));
            if (strCantidad != null) {
                cantidad = Integer.parseInt(request.getParameter("CANTIDAD"));
            }
            HttpSession session = request.getSession();
            FacturaDetalleComposite fdc;
            fdc = (FacturaDetalleComposite) session.getAttribute("FACTURA_DETALLE");

            DetalleFacturaBean detfacBean = new DetalleFacturaBean(conexion);
            fdc.setListaDetalle(detfacBean.editarCantidad(fdc.getListaDetalle(), codProd, cantidad));
            session.setAttribute("BOLETA_DETALLE", fdc);
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    public String getServletInfo() {
        return "Short description";
    }

}
